package com.onedec.attendance.service.impl;


import com.onedec.attendance.dao.OnedecAttendanceDao;
import com.onedec.attendance.dao.OnedecCheckingInDao;
import com.onedec.attendance.dao.OnedecEmpDao;
import com.onedec.attendance.entity.OnedecAttendance;

import com.onedec.attendance.entity.OnedecCheckingInExample;
import com.onedec.attendance.entity.OnedecEmp;
import com.onedec.attendance.service.AttendanceService;
import com.onedec.attendance.service.CheckinService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class AttendanceServiceImpl implements AttendanceService {
    @Resource
    private OnedecAttendanceDao attendanceDao;

    @Resource
    private OnedecEmpDao empDao;

    @Resource
    private OnedecCheckingInDao checkingInDao;

    @Override
    public int insertMorningAttend(OnedecAttendance attendance) throws Exception {
//        OnedecCheckingInExample checkingExm = new OnedecCheckingInExample();
//        checkingExm.createCriteria().and
//        checkingInDao.selectByExample();
        return attendanceDao.insert(attendance);
    }

    @Override
    public int insertAfternoonAttend(OnedecAttendance attendance) throws Exception {
        return attendanceDao.insert(attendance);
    }

    @Override
    public List<Map<String, Object>> selectAttends(Map<String, Object> map) throws Exception {
        return attendanceDao.selectAttends(map);
    }

    @Override
    public int selectAttendsCount(Map<String, Object> map) {
        return attendanceDao.countAttends(map);
    }


    @Override
    public int insertDailyAttend(){
        List<OnedecEmp> emps = empDao.selectByExample(null);
        int num=0;
        for(OnedecEmp emp:emps){
            OnedecAttendance mornAttend = new OnedecAttendance();
            OnedecAttendance afterAttend = new OnedecAttendance();
            Date date = new Date();
            mornAttend.setAttType("morning");
            mornAttend.setAttStatus(2);
            mornAttend.setAttEmpId(emp.getEmpId());
            mornAttend.setAttDate(date);
            afterAttend.setAttType("afternoon");
            afterAttend.setAttStatus(2);
            afterAttend.setAttEmpId(emp.getEmpId());
            afterAttend.setAttDate(date);
            attendanceDao.insert(mornAttend);
            num++;
            attendanceDao.insert(afterAttend);
            num++;
        }
        return num;
    }
}
